#include <QLocale>
#include <QDeclarativeContext>
#include <QtDeclarative/qdeclarative.h>
#include <QTranslator>
#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
#include "coinmodel.h"
#include "downloadfile.h"

Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QScopedPointer<QApplication> app(createApplication(argc, argv));
    QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());

    app->setOrganizationName("Janis");
    app->setApplicationName("NumismatMobile");

    QTranslator translator;
    if (translator.load(":/lang_" + QLocale::system().name()))
        app->installTranslator(&translator);

    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");

    CoinModel model(NULL, db);

    qmlRegisterType<DownloadFile>("NumismatMobile", 1, 0, "DownloadFile");
    qmlRegisterType<CoinModel>("NumismatMobile", 1, 0, "CoinModel");
    QDeclarativeContext *context = viewer->rootContext();
    context->setContextProperty("coinModel", &model);

    viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer->setMainQmlFile(QLatin1String("qrc:/qml/main.qml"));
    viewer->showExpanded();

    return app->exec();
}
